package com.mysafe.provision.persistence.account;

import com.mysafe.provision.model.account.Account;
import com.mysafe.provision.persistence.DAO;
import com.mysafe.provision.util.persistence.IEMFSingleton;
import java.io.Serializable;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.NonUniqueResultException;
import javax.persistence.Query;

public class AccountDAO extends DAO<Account> implements IAccountDAO,
		Serializable {
	private static final long serialVersionUID = 7887352505748119650L;

	@Inject
	public AccountDAO(IEMFSingleton emf) {
		super(emf);
	}

	public Account find(String login) {
		Account account = null;
		EntityManager em = getEntityManager();
		try {
			String sql = "select account.id from Account account where account.login = :login";

			Query query = em.createQuery(sql);
			query.setParameter("login", login);
			account = new Account((Integer) query.getSingleResult());
		} catch (NonUniqueResultException localNonUniqueResultException) {
		} catch (NoResultException localNoResultException) {
		} catch (Exception e) {
			e.printStackTrace();
			em.close();
		}
		return account;
	}
}